<?php 
namespace app\common\model;
use think\Model;
use think\Request;
/**
 * @Author: YeMiao
 * @Date:   2017-07-31 11:24:07
 * @Last Modified by:   YeMiao
 * @Last Modified time: 2017-08-05 11:36:05
 */

class AdminLog extends Model{

	protected $resultSetType = 'collection';
	protected $updateTime = false;


	public function get_list($page = null){
		if(input('session.user')){
			$user = input('session.user');
		}else{
			$user = input('cookie.user');
		}
		if($page != null){
			$log = $this->where('user',$user)->order('create_time desc')->paginate($page['limit']);
		}else{
			$log = $this->where('user',$user)->order('create_time desc')->select()->toArray();
		}		
		return $log;
	}
	/**
	*$user 默认为登录的session
	*添加用户日志
	*/
	public function add_log($str,$user = null){
		$request = Request::instance();
		if($user == null){
			if(input('session.user')){
				$user = input('session.user');
			}else{
				$user = input('cookie.user');
			}			
		}
		$data = [
			'log' => $str,
			'user' => $user,
			'ip' => $request->ip(),
			'method' => $request->method(),
			'agent' => $request->header('user-agent')
		];
		$this->save($data);
	}
}

 ?>
